﻿namespace FitnessTracker.Packet
{
    using System;
    using System.Text;

    public class HxMPacketHeader
    {
        public const ushort Length = 11;
        private readonly byte[] rowBytes;

        public HxMPacketHeader(byte[] buffer)
        {
            this.rowBytes = buffer;
        }

        public ushort FirmwareID
        {
            get
            {
                return BitConverter.ToUInt16(this.rowBytes, HxMPacketStructure.FirmwareIDOffset);
            }
        }

        public string FirmwareVer
        {
            get
            {
                return Encoding.ASCII.GetString(this.rowBytes, HxMPacketStructure.FirmwareVersionOffset, 2);
            }
        }

        public ushort HardwareID
        {
            get
            {
                return BitConverter.ToUInt16(this.rowBytes, HxMPacketStructure.HardwareIDOffset);
            }
        }

        public string HardwareVer
        {
            get
            {
                return Encoding.ASCII.GetString(this.rowBytes, HxMPacketStructure.HardwareVersionOffset, 2);
            }
        }

        public override string ToString()
        {
            return string.Format(
                "Firmware ID:{0}" + Environment.NewLine +
                "Firmware Ver:{1}" + Environment.NewLine +
                "Hardware ID:{2}" + Environment.NewLine +
                "Harware Ver:{3}",
                this.FirmwareID,
                this.FirmwareVer,
                this.HardwareID,
                this.HardwareVer);
        }
    }
}
